import sqlite3

# 连接到数据库
conn = sqlite3.connect('aichat.db')
cursor = conn.cursor()

target_session_id = '54f4e3b0-b4ff-4d36-ab1e-e9fb604cad76'

print(f"准备清空会话ID: {target_session_id} 的历史记录")

# 统计要删除的记录数
cursor.execute('SELECT COUNT(*) FROM messages WHERE session_id = ?', (target_session_id,))
count = cursor.fetchone()[0]
print(f"将要删除的消息数量: {count}")

# 删除该会话的所有记录
cursor.execute('DELETE FROM messages WHERE session_id = ?', (target_session_id,))
conn.commit()

print(f"已成功清空会话历史记录")
print(f"删除的记录数量: {cursor.rowcount}")

# 验证删除结果
cursor.execute('SELECT COUNT(*) FROM messages WHERE session_id = ?', (target_session_id,))
remaining = cursor.fetchone()[0]
print(f"会话中剩余的消息数量: {remaining}")

conn.close()
